package com.southgis.ibase.sql.builder;

import java.util.Objects;

import com.southgis.ibase.sql.utils.DatabaseFunc;

public class ClauseColumn extends TableColumn
{
	DatabaseFunc func;
	ClauseItem column;
	
	public ClauseColumn(ClauseItem ci, String alias)
	{
		super("", "", alias);
		column=ci;
	}
	
	public ClauseItem getColumn()
	{
		return column;
	}
	
	public void setColumn(ClauseItem item)
	{
		this.column=item;
	}
	
	public DatabaseFunc getFunc()
	{
		return func;
	}

	public void setFunc(DatabaseFunc func)
	{
		this.func = func;
	}
	
	
	@Override
	protected void fillName(StringBuilder sb)
	{
		sb.append("(");
		column.func=this.func;
		column.toSql(sb);
		sb.append(")");
	}
	
	@Override
	public boolean equals(Object obj)
	{
		if(obj==null) return false;
		if(this==obj) return true;
		if(!(obj instanceof ClauseColumn)) return false;
		ClauseColumn comp=(ClauseColumn)obj;
		return Objects.equals(this.column, comp.column);
	}
	@Override
	public int hashCode()
	{
		return Objects.hash(this.getClass(), this.column);
	}
	
	@Override
	public String toString()
	{
		return "{complex field}@["+this.getAlias()+"]";
	}

}
